// router
package bootstrap

import (
	"github.com/codegangsta/martini"
	"github.com/martini-contrib/binding"
	"github.com/martini-contrib/render"
	"martini_template/controllers/common"
	"martini_template/controllers/member"
	"martini_template/form"
)

func InitRouter() {
	//404处理
	App.NotFound(func(r render.Render) {
		r.JSON(404, "Not Found")
		return
	})

	//	App.Group("/v1/admin/user", func(rt martini.Router) {
	//		var c controllers_admin.User
	//		var loginForm form.LoginForm
	//		rt.Post("/login", binding.Bind(loginForm), c.Login)
	//		rt.Post("/add", c.Add)
	//		rt.Get("/profile/:id", c.Authorize, c.Profile)
	//		rt.Put("/update", c.Update)
	//		rt.Delete("/delete", c.Delete)
	//	})

	//公用模块
	App.Group("/v1/common", func(rt martini.Router) {
		var c controllers_common.Upload
		var uploadForm form.UploadForm
		rt.Post("/upload", binding.MultipartForm(uploadForm), c.UploadFile)
		var logForm form.LogForm
		var lCtrl controllers_common.OpLog
		rt.Post("/oplog", binding.Bind(logForm), lCtrl.Save)
	})

	//会员模块(v1)的路由
	App.Group("/v1/member", func(rt martini.Router) {
		var c controllers_member.Member
		var mForm form.MemberForm
		var loginForm form.LoginForm
		var atForm form.AccessTokenForm
		//注册
		rt.Post("/register", binding.Bind(mForm), c.Register)
		//登录
		rt.Post("/login", binding.Bind(loginForm),c.Login)
		//更新
		rt.Put("/update", binding.Bind(mForm),binding.Bind(atForm),c.CheckAccessToken,c.Update)
		//修改密码
		rt.Put("/password", binding.Bind(mForm),binding.Bind(atForm),c.CheckAccessToken,c.Password)
		//会员信息
		rt.Get("/info",binding.Bind(mForm),binding.Bind(atForm),c.CheckAccessToken,c.Info)
		//绑定
		rt.Put("/banding",binding.Bind(mForm),binding.Bind(atForm),c.CheckAccessToken,c.Banding)
	})
}
